import {Component} from 'react';

export default class Demo extends Component{

      state={
          color:"red"
      }

   handleClick=(e)=>{
       if(this.state.color==='red'){
        this.setState({
            color:"green" 
         })
       }else{
        this.setState({
            color:"red" 
         }) 
       }
      
   }

    render(){
        let {color} = this.state;
        return(
            <div>
                <button onClick={this.handleClick} >点击改变颜色</button>
                 <h2 style={{color}}>显示的内容</h2>  
            </div>
        )
    }
} 

